# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

inherit eutils java-pkg

DESCRIPTION="NetBeans ${PV} IDE for Java"

IUSE="kde gnome debug"
HOMEPAGE="http://www.netbeans.org"

SRC_URI="netbeans-4_0-src-ide_sources.tar.bz2"

SLOT="4.0"

#We need to add many licenses in here. 
LICENSE="GPL-2 Apache-1.1 sun-bcla-j2ee JPython SPL"
KEYWORDS="~x86"

DEPEND=">=virtual/jdk-1.4.2
		>=dev-java/ant-1.6.1"
#		=dev-java/xerces-2.6.2*"

RDEPEND=">=virtual/jre-1.4.2"

S=${WORKDIR}/netbeans-src
BUILDDESTINATION="${S}/nbbuild/netbeans"		
		
src_unpack () 
{
	unpack $A
	cd ${S}/libs/external/
#	rm -fr xerces-2.6.2.jar.scrambled
#	java-pkg_jar-from xerces-2 xercesImpl.jar xerces-2.6.2.jar	
	#removing tomcat
#	rm -fr tomcatint translatedfiles/src/tomcatint
}
src_compile()
{
	local antflags=""
	! use debug && antflags="${antflags} -Dno-deprecation"

	# The build will attempt to display graphical
	# dialogs for the licence agreements if this is set.
	unset DISPLAY
	
	# Move into the folder where the build.xml file lives.
	cd ${S}/nbbuild
	
	# Specify the build-nozip target otherwise it will build
	# a zip file of the netbeans folder, which will copy directly.
	yes yes 2>/dev/null | 	ant $antflags build-nozip || die "Compiling failed!"
}

src_install()
{	
	local DESTINATION="/usr/share/netbeans-${SLOT}"

	# Remove non-x86 Linux binaries
	find $S -name "*.exe" -o -name "*.cmd" -o -name "*.dll" | xargs rm -f 
	
	cd ${BUILDDESTINATION}
	
	#Documentation
	dodoc build_info
	dohtml CREDITS.html README.html netbeans.css
	rm -f build_info CREDITS.html README.html netbeans.css

	#The program itself
	dodir $DESTINATION
	cp -a * ${D}/$DESTINATION

	dodir /usr/bin
	dosym ${DESTINATION}/bin/netbeans /usr/bin/netbeans-${SLOT}

	# If either Gnome or KDE are installed, then install the icons.
	if use gnome || use kde; then
		einfo "Adding icons and shorcuts...."
		doicon ${BUILDDESTINATION}/nb4.0/netbeans.png
		make_desktop_entry netbeans Netbeans netbeans Development
	fi
}
